package org.easy.core.enums;


/**
 * @author hyk
 * @date 2019/2/26
 * @Description
 */
public enum FileType {

    /**
     * Adobe Acrobat.
     */
    PDF("application/pdf", 101, "pdf", "255044462D312E", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOC("application/msword", 102, "doc", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOT("application/msword", 103, "dot", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document", 104, "docx", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOTX("application/vnd.openxmlformats-officedocument.wordprocessingml.template", 105, "dotx", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOCM("application/vnd.ms-word.document.macroEnabled.12", 106, "docm", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Word.
     */
    DOTM("application/vnd.ms-word.template.macroEnabled.12", 107, "dotm", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Ppt
     */
    PPT("application/vnd.ms-powerpoint", 108, "ppt", "D0CF11E0", FileGroup.FILE),

    /**
     * MS Ppt
     */
    PPTX("application/vnd.openxmlformats-officedocument.presentationml.presentation", 109, "pptx", "006E1EF0", FileGroup.FILE),

    /**
     * MS Ppt
     */
    PPTM("application/vnd.ms-powerpoint.presentation.macroEnabled.12", 110, "pptm", "006E1EF0", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLS("application/vnd.ms-excel", 111, "xls", "0902060000001000B9045C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 112, "xlsx", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLSM("application/vnd.ms-excel.sheet.macroEnabled.12", 113, "xlsm", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLTX("application/vnd.openxmlformats-officedocument.spreadsheetml.template", 114, "xltx", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLTM("application/vnd.ms-excel.template.macroEnabled.12", 115, "xltm", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLSB("text/html", 116, "xlsb", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * MS Excel
     */
    XLAM("text/html", 117, "xlam", "0904060000001000F6055C00", FileGroup.FILE),

    /**
     * Rich Text Format.
     */
    RTF("application/msword", 118, "rtf", "7B5C727466", FileGroup.FILE),

    /**
     * Email [thorough only].
     */
    EML("message/rfc822", 119, "eml", "44656C69766572792D646174653A", FileGroup.FILE),

    /**
     * Outlook Express.
     */
    DBX("application/x-dbx", 120, "dbx", "CFAD12FEC5FD746F", FileGroup.FILE),

    /**
     * Outlook (pst).
     */
    PST("", 121, "pst", "2142444E", FileGroup.FILE),

    /**
     * MS Access.
     */
    MDB("application/msaccess", 122, "mdb", "5374616E64617264204A", FileGroup.FILE),

    /**
     * XML.
     */
    XML("text/xml", 123, "xml", "3C3F786D6C", FileGroup.FILE),

    /**
     * HTML.
     */
    HTML("text/html", 124, "html", "68746D6C3E", FileGroup.FILE),

    /**
     * JEPG.
     */
    JPG("image/jpeg", 201, "jpg", "FFD8FF", FileGroup.IMAGE),

    /**
     * JEPG.
     */
    JPEG("image/jpeg", 202, "jpeg", "FFD8FF", FileGroup.IMAGE),

    /**
     * PNG.
     */
    PNG("image/png", 203, "png", "89504E47", FileGroup.IMAGE),

    /**
     * GIF.
     */
    GIF("image/gif", 204, "gif", "47494638", FileGroup.IMAGE),

    /**
     * Windows Bitmap.
     */
    BMP("application/x-bmp", 205, "bmp", "424D", FileGroup.IMAGE),

    /**
     * TIFF.
     */
    TIFF("image/tiff", 206, "tiff", "49492A00", FileGroup.IMAGE),

    /**
     * CAD.
     */
    DWG("application/x-dwg", 207, "dwg", "41433130", FileGroup.IMAGE),

    /**
     * Adobe Photoshop.
     */
    PSD("", 208, "psd", "38425053", FileGroup.IMAGE),

    /**
     * MP4
     */
    MP4("video/mpeg4", 301, "mp4", "00000020667479706d70", FileGroup.VIDEO),

    /**
     * AVI.
     */
    AVI("video/avi", 302, "avi", "41564920", FileGroup.VIDEO),

    /**
     * Quicktime.
     */
    MOV("video/quicktime", 303, "mov", "6D6F6F76", FileGroup.VIDEO),

    /**
     * MPEG (mpg).
     */
    MPG("video/mpg", 304, "mpg", "000001BA", FileGroup.VIDEO),

    /**
     * Windows Media.
     */
    ASF("video/x-ms-asf", 305, "asf", "3026B2758E66CF11", FileGroup.VIDEO),

    /**
     * MIDI.
     */
    MID("audio/mid", 306, "mid", "4D546864", FileGroup.VIDEO),

    MP3("audio/mp3", 401, "mp3", "494433", FileGroup.AUDIO),

    APE("voice/ape", 402, "ape", "", FileGroup.AUDIO),

    FLAC("voice/flac", 403, "flac", "", FileGroup.AUDIO),

    AAC("voice/aac", 404, "aac", "", FileGroup.AUDIO),

    SPX("voice/speex", 405, "spx", "369D019EA0000068E", FileGroup.AUDIO),

    /**
     * Wave.
     */
    WAV("audio/wav", 406, "wav", "57415645", FileGroup.AUDIO),

    /**
     * Real Audio.
     */
    RAM("audio/x-pn-realaudio", 407, "ram", "2E7261FD", FileGroup.AUDIO),

    /**
     * Real Media.
     */
    RM("application/vnd.rn-realmedia", 408, "rm", "2E524D46", FileGroup.AUDIO),

    WMA("audio/x-ms-wma", 409, "wma", "3026B2758E66", FileGroup.AUDIO),


    AMR("audio/amr", 410, "amr", "2321414D520A0CC63", FileGroup.AUDIO),

    ZIP("application/x-zip-compressed", 411, "zip", "3026B2758E616", FileGroup.FILE);

    private String value = "";

    private String contentType = "";

    private int type = 0;

    private String suffix = "";

    private FileGroup group = null;

    /**
     * Constructor.
     *
     * @param type
     */
    FileType(String contentType, int type, String suffix, String value, FileGroup group) {
        this.contentType = contentType;
        this.type = type;
        this.suffix = suffix;
        this.value = value;
        this.group = group;
    }

    public String getValue() {
        return value;
    }

    public String getContentType() {
        return contentType;
    }

    public int getType() {
        return type;
    }

    public String getSuffix() {
        return suffix;
    }

    public FileGroup getGroup() {
        return group;
    }

    public static int getTypeBySuffix(String suffix) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getSuffix().equalsIgnoreCase(suffix)) {
                return fileType.getType();
            }
        }
        return 0;
    }

    public static String getContentTypeBySuffix(String suffix) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getSuffix().equalsIgnoreCase(suffix)) {
                return fileType.getContentType();
            }
        }
        return "";
    }

    public static String getContentTypeByType(int type) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getType() == type) {
                return fileType.getContentType();
            }
        }
        return "";
    }

    public static String getSuffixByType(int type) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getType() == type) {
                return fileType.getSuffix();
            }
        }
        return "";
    }

    public static FileType getFileTypeByType(int type) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getType() == type) {
                return fileType;
            }
        }
        return null;
    }

    public static FileGroup getGroupBySuffix(String suffix) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getSuffix().equalsIgnoreCase(suffix)) {
                return fileType.getGroup();
            }
        }
        return null;
    }
}
